package com.example.ai

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.statusBars
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import androidx.core.view.WindowCompat
import androidx.lifecycle.ViewModelProvider
import com.example.ai.model.data.ChatRoomData
import com.example.ai.model.data.MessageDatabase
import com.example.ai.model.viewmodel.MessageViewModel
import com.example.ai.model.viewmodel.ViewModelFactory
import com.example.ai.page.VideoChatPage
import com.example.ai.ui.theme.AITheme

class VideoChatActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val database = MessageDatabase.getInstance(this@VideoChatActivity)
        val title = intent.getStringExtra(MainActivity.ARG_TITLE) ?: MainActivity.DEFAULT_TITLE
        val id = intent.getStringExtra(MainActivity.ARG_ID) ?: MainActivity.DEFAULT_ID
        val viewModel = ViewModelProvider(this@VideoChatActivity, ViewModelFactory {
            MessageViewModel(
                chatRoom = ChatRoomData(id, title),
                database,
                useNewSource = true,
                saveToRoom = false
            )
        })[MessageViewModel::class.java].apply {
            prepare()
        }
        setContent {
            AITheme {
                // A surface container using the 'background' color from the theme
                Surface(
                    modifier = Modifier
                        .fillMaxSize()
                        .windowInsetsPadding(WindowInsets.statusBars)
                        .windowInsetsPadding(WindowInsets.navigationBars),
                    color = MaterialTheme.colorScheme.background
                ) {
                    VideoChatPage(title = title, viewModel = viewModel)
                }
            }
        }
    }
}
